import JSEncrypt from 'jsencrypt';

// 公钥
export const publicKey =
  'MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAJ44UT2hwu8KFg5un9Hh6bMd3vma7SbxNGSNpy+/u650wCmqs0FivboWIYYZVjnz+itlPP34LS+RnD0KuziOwlkCAwEAAQ==';

// 私钥
export const privateKey =
  'MIIBVAIBADANBgkqhkiG9w0BAQEFAASCAT4wggE6AgEAAkEAnjhRPaHC7woWDm6f0eHpsx3e+ZrtJvE0ZI2nL7+7rnTAKaqzQWK9uhYhhhlWOfP6K2U8/fgtL5GcPQq7OI7CWQIDAQABAkEAk8VzkwV2w7z+1qHZYLQHigPXEfbxkZJr5ZIrWLxRNOBXQKO6ixdkWHMb6Mx3WkSA1BDTC1qkszMtw10etDm/FQIhAOvXZe6Ikmop/mB+20k23qCxDWGzBU6hLIzkYczxEDUvAiEAq75vB974Uh/xuekF5bx/bmmeh7tl1a+f1uTyNuAzLvcCIDsya9F90lJ3i/Qoo14zOZpYFqXJS7G63vXWdX39nDXdAiAcQJaJR++3qtOcDq5OraSU6EEQ+Q32ig6UTlNeHaGt3wIgBESNUuCbwvTT+Rcw1yaRyp9/vPeXZxBG4e3cY/2ywX4=';

/**
 * RSA加密
 * @param plainText 明文
 * @returns {*} 密文
 */
export function encryptByRSA(plainText: any) {
  const encryptor = new JSEncrypt();
  encryptor.setPublicKey(publicKey);
  return encryptor.encrypt(plainText);
}

/**
 * RSA解密
 * @param cipherText 密文
 * @returns {*} 明文
 */
export function decryptByRSA(cipherText: any) {
  const decrypter = new JSEncrypt();
  decrypter.setPrivateKey(privateKey);
  return decrypter.decrypt(cipherText);
}
